<?php

/**
 * LEAGUEMan
 * 
 * Copyright (C) 2007 Marko Bischof
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

?>

<h3><?php echo $this->project->getName();?> - Matrix</h3>

<table width="100%" class="contentpane">

<?php 
$k = 0;

ob_start();

$teams = $this->project->getTeams();

for($rows = 0; $rows <= count($teams); $rows++){
	
	$trow =  ($rows == 0) ? $teams[0] : $teams[$rows - 1];
	
	echo '<tr class="sectiontableentry1">';
	
	for($cols = 0; $cols <= count($teams); $cols++){
		$text = "";
		
		$tcol = ( $cols == 0 ) ? $teams[0] : $teams[$cols - 1];
		
		$id = $trow->team_id . ':' . $tcol->team_id;
		
		$matchid = isset($this->matchlist[$id]) ? $this->matchlist[$id] : 0;
		
		$link = sefRelToAbs("index.php?option=com_leagueman&amp;func=teaminfo&amp;tm={$trow->teammap_id}&amp;Itemid={$this->Itemid}");
		$match_link = sefRelToAbs("index.php?option=com_leagueman&amp;func=mathcinfo&amp;m={$matchid}&amp;Itemid={$this->Itemid}");
		
		if($rows == 0 && $cols == 0) echo '<td class="sectiontableentry1" width="160" align="center">&nbsp;</td>';
		else if($rows == 0) printf('<td class="sectiontableentry1" width="30" title="%s">&nbsp;</td>', $tcol->team_name); //picture columns
		else if($cols == 0) printf('<td class="sectiontableheader" width="160" align="right" nowrap="nowrap"><a href="%s">%s</a></td>', $link, $trow->team_name); // named rows
		else if($rows == $cols) echo '<td class="sectiontableheader" width="30">&nbsp;</td>'; //impossible matches
		else{
			echo '<td width="30" align="center">' . @implode($this->results[$id], "<br/>") . '</td>';
		}
	}
	
	$k = 1 - $k;
	echo '<td nowrap="nowrap">&nbsp;</td></tr>';
}

	$matrix = ob_get_contents();
ob_end_clean();

echo $matrix;

?>

</table>